<script setup>
import { ref } from 'vue'
import Button from '@/components/Button.vue'
import InputLogin from '../../components/InputLogin.vue'
import { useRouter } from 'vue-router'

const isActive = ref(false)
const toggleActive = (state) => {
  isActive.value = state
}

// 表单数据
const SigninFormData = ref({
  userId: 'pxh',
  password: ''
})
const SignupFormData = ref({
  userId: 'zy',
  password: '',
  repassword: '',
  jwt: ''
})

const router = useRouter()
const login = () => {
  router.push('/')
  console.log(1)
}
const register = () => {
  router.push('/')
  console.log(2)
}
</script>

<template>
  <div class="container" id="container" :class="{ active: isActive }">
    <div class="form-container sign-up">
      <form>
        <h1>注册账户</h1>
        <span>没有令牌？请向管理员申请</span>
        <InputLogin
          type="text"
          v-model="SignupFormData.userId"
          width="100%"
          inputClass="input-sign-in-userId"
          spanClass="span-icon-userId"
        ></InputLogin>
        <InputLogin
          type="password"
          v-model="SignupFormData.password"
          width="100%"
          inputClass="input-sign-in-password"
          spanClass="span-icon-password"
        ></InputLogin>
        <InputLogin
          type="repassword"
          :confirmInfo="SignupFormData.password"
          v-model="SignupFormData.repassword"
          width="100%"
          inputClass="input-sign-in-repassword"
          spanClass="span-icon-password"
        ></InputLogin>
        <InputLogin
          type="text"
          confirmInfo="令牌"
          v-model="SignupFormData.jwt"
          width="100%"
          inputClass="input-sign-in-jwt"
          spanClass="span-icon-jwt"
        ></InputLogin>
        <Button
          text="注册"
          extraClass="btn-container"
          @click.prevent="register"
        ></Button>
      </form>
    </div>
    <div class="form-container sign-in">
      <form>
        <h1>登录</h1>
        <span>使用账号密码登录</span>
        <InputLogin
          type="text"
          v-model="SigninFormData.userId"
          width="100%"
          inputClass="input-sign-in-userId"
          spanClass="span-icon-userId"
        ></InputLogin>
        <InputLogin
          type="password"
          v-model="SigninFormData.password"
          width="100%"
          inputClass="input-sign-in-password"
          spanClass="span-icon-password"
        ></InputLogin>

        <Button
          text="登录"
          extraClass="btn-container"
          @click.prevent="login"
        ></Button>
      </form>
    </div>
    <div class="toggle-container">
      <div class="toggle">
        <div class="toggle-panel toggle-left">
          <h1>你好，新朋友</h1>
          <p>使用您的个人详细信息及管理员令牌注册以使用系统的所有功能</p>
          <Button
            text="去登录"
            extraClass="hidden"
            id="login"
            @click="toggleActive(false)"
          >
          </Button>
        </div>
        <div class="toggle-panel toggle-right">
          <h1>欢迎回来</h1>
          <p>登录账户并使用系统的所有功能</p>
          <Button
            text="去注册"
            extraClass="hidden"
            id="register"
            @click="toggleActive(true)"
          >
          </Button>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
@use '@/assets/scss/abstracts/mixins' as *;
@use '@/assets/scss/abstracts/variables' as *;
@use '@/assets/scss/base/animation' as *;
@use 'sass:color';
.container {
  background-color: $color-white;
  border-radius: 3rem;
  box-shadow: 0 0.5rem 1.5rem rgba($color-black, 0.35);
  // position: relative;
  @include absCenter;
  overflow: hidden;
  width: 87rem;
  min-height: 58rem;
  max-width: 100%;

  .form-container {
    position: absolute;
    top: 0;
    height: 100%;
    transition: all 0.6s ease-in-out;
    background-color: inherit;

    span {
      font-size: 1.4rem;
    }

    .btn-container {
      padding: 1rem 3rem;
      font-weight: 500;
      margin-top: -0.5rem;

      &:hover {
        background-color: color.adjust($color-primary-dark-2, $lightness: -10%);
      }
    }

    form {
      height: 100%;
      @include flexColumnCenter;
      gap: 1.5rem;
      padding: 0 5rem;
    }
  }

  .sign-in {
    left: 0;
    width: 50%;
    z-index: 2;
  }

  .sign-up {
    left: 0;
    width: 50%;
    opacity: 0;
    z-index: 1;
  }

  .input-sign-in-userId {
    &::before {
      content: '用户名';
    }
  }

  :deep(.span-icon-userId) {
    background: url('@/assets/svg/user.svg') no-repeat center / 100%;
  }

  .input-sign-in-password {
    &::before {
      content: '密码';
    }
  }

  :deep(.span-icon-password) {
    background: url('@/assets/svg/小眼睛-闭.svg') no-repeat center / 100%;
    cursor: pointer;
  }

  .input-sign-in-repassword {
    &::before {
      content: '再次确认密码';
    }
  }

  .input-sign-in-jwt {
    &::before {
      content: '令牌';
    }
  }

  :deep(.span-icon-jwt) {
    background: url('@/assets/svg/令牌.svg') no-repeat center / 100%;
  }

  .toggle-container {
    position: absolute;
    top: 0;
    left: 50%;
    width: 50%;
    height: 100%;
    overflow: hidden;
    transition: all 0.6s ease-in-out;
    border-radius: 15rem 0 0 10rem;
    z-index: 10;

    .toggle {
      background: linear-gradient(
        to right,
        $color-primary-light,
        $color-primary
      );
      position: relative;
      color: $color-white;
      left: -100%;
      height: 100%;
      width: 200%;
      transform: translateX(0);
      transition: all 0.6s ease-in-out;

      .toggle-panel {
        position: absolute;
        width: 50%;
        height: 100%;
        @include flexColumnCenter;
        padding: 0 3rem;
        text-align: center;
        top: 0;
        transform: translateX(0);
        transition: all 0.6s ease-in-out;

        p {
          font-size: 1.4rem;
          line-height: 2rem;
          letter-spacing: 0.3px;
          margin: 2rem 0;
        }

        .hidden {
          border: 1px solid $color-white;
          background-color: transparent;
          padding: 1rem 3rem;
        }
      }

      .toggle-left {
        transform: translateX(-200%);
      }

      .toggle-right {
        right: 0;
        transform: translateX(0);
      }
    }
  }

  &.active {
    .sign-in {
      transform: translateX(100%);
    }

    .sign-up {
      transform: translateX(100%);
      opacity: 1;
      z-index: 5;
      animation: move 0.6s;
    }

    .toggle-container {
      transform: translateX(-100%);
      border-radius: 0 15rem 10rem 0;

      .toggle {
        transform: translateX(50%);
      }

      .toggle-left {
        transform: translateX(0);
      }

      .toggle-right {
        transform: translateX(200%);
      }
    }
  }
}
</style>
